package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.SystemInfoService;

@WebServlet("/SystemInfoServlet")
public class SystemInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public SystemInfoServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SystemInfoService service = new SystemInfoService();
		String operation = request.getParameter("operation");
		switch(operation) {
		case "get" : response.getWriter().write(service.getInfoJson());break;
		case "set" : 
			String title = request.getParameter("title");
			String company = request.getParameter("company");
			String icp = request.getParameter("icp");
			service.setInfo(title, company, icp);
		}
	}
}
